<?php
	$result = $database->query("SELECT * FROM ".TBL_CATEGORIES." ORDER BY type ASC, category ASC");
	$num_rows = mysql_num_rows($result);
	
	echo "<script type=\"text/javascript\">";
	echo "var knowledge = new Array();";
	$knowledge_count = 0;
	echo "var ability = new Array();";
	$ability_count = 0;
	echo "var commodity = new Array();";
	$commodity_count = 0;
	echo "var transportation = new Array();";
	$transportation_count = 0;
	echo "var materials = new Array();";
	$materials_count = 0;
	echo "var land = new Array();";
	$land_count = 0;
	for($i=0;$i<$num_rows;$i++)
	{
		$type = mysql_result($result,$i,"type");
		$category = mysql_result($result,$i,"category");
		if($type == "Knowledge")
		{
			echo "knowledge[$knowledge_count] = \"$category\";";
			$knowledge_count++;
		}
		else if($type == "Ability")
		{
			echo "ability[$ability_count] = \"$category\";";
			$ability_count++;
		}
		else if($type == "Commodity")
		{
			echo "commodity[$commodity_count] = \"$category\";";
			$commodity_count++;
		}
		else if($type == "Transportation")
		{
			echo "transportation[$transportation_count] = \"$category\";";
			$transportation_count++;
		}
		else if($type == "Raw Materials")
		{
			echo "materials[$materials_count] = \"$category\";";
			$materials_count++;
		}
		else if($type == "Land")
		{
			echo "land[$land_count] = \"$category\";";
			$land_count++;
		}
	}
	echo "</script>";
?>
<script type="text/javascript">
function setOptions(chosen)
{
	var selbox = document.getElementById("category");
	
	while ( selbox.options.length ) selbox.options[0] = null;
	
	if (chosen == "")
	{
		selbox.options[0] = new Option("-All Categories-","");
	}
	else if (chosen == "Knowledge")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<knowledge.length;j++)
		{
			selbox.options[j+1] = new Option(knowledge[j],knowledge[j]);
		}
	}
	else if (chosen == "Ability")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<ability.length;j++)
		{
			selbox.options[j+1] = new Option(ability[j],ability[j]);
		}
	}
	else if (chosen == "Commodity")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<commodity.length;j++)
		{
			selbox.options[j+1] = new Option(commodity[j],commodity[j]);
		}
	}
	else if (chosen == "Transportation")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<transportation.length;j++)
		{
			selbox.options[j+1] = new Option(transportation[j],transportation[j]);
		}
	}
	else if (chosen == "Raw Materials")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<materials.length;j++)
		{
			selbox.options[j+1] = new Option(materials[j],materials[j]);
		}
	}
	else if (chosen == "Land")
	{
		selbox.options[0] = new Option("-All Categories-","");
		for(j=0;j<land.length;j++)
		{
			selbox.options[j+1] = new Option(land[j],land[j]);
		}
	}
}
</script>